<template>
	<view>
		<search @confirm="search()"></search>
		<view class="deviceList">
			<view class="_header" v-if="devList.length > 0">
				共<text>{{num}}</text>条记录
			</view>
			<view class="_list" v-for="(item,index) in devList" :key="index" @click="choose(item)">
				<view>
					<text>{{item.name}}</text>
					<text class="carCode">{{item.carCode}}</text>
				</view>
				<text>{{item.carCode}}</text>
				<text>{{item.content}}</text>
			</view>
		</view>
	</view>
</template>

<script>
	import search from './components/search.vue'
	export default {
		components:{
			search
		},
		data() {
			return {
				num:0,
				devList:[
					
				]
			}
		},
		methods: {
			// 搜索
			search(value){
				let result = value.trim()
				
				if(result){
					
					this.devList = [
						{
							name:"设备A",
							carCode:'湘A99999',
							ip:"55-12-34-64-87-76",
							content:'A186'
						},
						{
							name:"设备B",
							carCode:'湘B66666',
							ip:"55-12-34-64-87-79",
							content:'A186'
						}
					]
					this.num = this.devList.length > 999 ? '999+' : this.devList.length
				}else{
					this.devList = []
					uni.showToast({
					    title: '请输入搜索内容',
							icon:'none',
					    duration: 2000
					});
				}
			},
			// 选择
			choose(item){
				let page = getCurrentPages()
				let beforePage = page[page.length - 2]
				uni.navigateBack({
					success:()=>{
						beforePage.$vm.updateConfig(item)
					}
				})
			}
		}
	}
</script>

<style scoped>
	._header{
		height: 80rpx;
		background-color: #FFFFFF;
		border-bottom: 1px solid #E9E9E9;
		line-height: 80rpx;
		font-size: 26rpx;
		padding: 0 20rpx;
		letter-spacing: 4rpx;
	}
	._header >text{
		color: #FB5151;
	}
.deviceList{
	margin-top: 120rpx;
}
._list{
	/* height: 90rpx; */
	padding: 20rpx;
	display: flex;
	flex-direction: row;
	justify-content: space-between;
	align-items: flex-start;
	border-bottom: 1px solid #D7D7D7;
}
._list>view{
	display: flex;
	flex-direction: column;
}
.carCode{
	margin-top: 4rpx;
	font-size: 24rpx;
	color: #8B8B8B;
}
</style>
